Skip to content

Refactor core image #486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

youngmoneee
Copy link
Contributor

@youngmoneee youngmoneee commented Mar 21, 2024

Summary

Refactored Image Object

Description

In the case of the original image objects, we initialized them by passing both base64 and URL as constructor arguments, and returned their values through the getUrl and getBase64 methods.

However, this approach made it challenging to clearly indicate small differences between various providers leading to scalability issues when adding new types beyond base64 and URL.

To solve this, we have separated the original Image object into the Image and ImageType interfaces. Each module defines an enum that implements the ImageType interface (e.g., OpenAiImageType, etc.), allowing us to distinguish between the image's provider and format. This enum can be flexibly applied to situations like the Request's Response Format.

//  example code
  (req, res) -> {
    return switch(req.responseFormat()) {
      case URL -> new MyUrlImage(res.data());
      case B64 -> new MyBase64Image(res.data());
      default -> throw new MyException("Unsupported type")
  }
}

Moreover, through the Image interface, all image objects can be uniformly treated, making the design easily adaptable even when new response formats or providers are added.

Please kindly review the proposed structure change to resolve this issue.

I am requesting your review as you are the most recent committer to this file.
@markpollack

Thank you.

Add a common interface for the extension of the ImageType enum.
Implemented image type objects for each provider.
Added Image interface and abstract class for flexible extension.
Developed image implementations for each provider.
modified Test code
@markpollack
Copy link
Member

Thanks, trying to catch up on many things, i'll get to it. Appreciate the PR.

Implemented Image Types and Implementations
@markpollack
Copy link
Member

This is old and there is no spring-ai-core anymore! :) Thanks though, too bad we didn't get to it MUCH earlier.

@markpollack markpollack closed this May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants